library(foreign)
library(ggplot2)
library(tidyr)
library(plyr)


# Figure 2: Preferred Nuclear Theory (Self-Reported)

setwd("/Users/dmin/Dropbox/Replication_Data/Paper_3/")

Dat <- read.csv("Paper_3_Data_Clean.csv", stringsAsFactors = FALSE)

p <- ggplot(Dat, aes(x=as.factor(NuclearTheory), fill=as.factor(Nuclear))) + geom_bar() +
  ylab("Count") + xlab("Preferred Nuclear Theory") + theme(plot.title = element_text(hjust = 0.5), plot.subtitle = element_text(hjust = 0.5)) +
  ggtitle("") +
  theme_bw() +
  scale_fill_manual(breaks=levels(factor(0:1)), values=c("0"="cornflowerblue", "1" ="coral1"), labels=c("No", "Yes"), name="Supported Nuclear Use\n(At Any Threshold)")+
  scale_x_discrete(labels=c("Never-Evers", "Existential\nDeterrence", "Offense/\nDefense", "Utilitarian"))

g <- p + annotate("text", x=1, y=10, label="68%") + 
  annotate("text", x=2, y=10, label="90.2%") + 
  annotate("text", x=3, y=10, label="95%") + 
  annotate("text", x=4, y=10, label="97.1%")+
  annotate("text", x=1, y=575, label="32%") + 
  annotate("text", x=2, y=235, label="9.8%") + 
  annotate("text", x=3, y=325, label="5.0%") + 
  annotate("text", x=4, y=185, label="2.9%")

g

ggsave("Image_2.png", plot=g, width=2000, height=2000, units=c("px"))
# 
# 
# 
# 181+384
# sum(!is.na(Dat$Nuclear))
# (22+16+5)/(203+299+169)
# 
# 564/1279
# 
# 32/6.4
# Combined <- ddply(Dat, c("Nuclear", "NuclearTheory"),
#                   summarise, N = sum(!is.na(Nuclear)),
#                   xbar = mean(Nuclear, na.rm=T),
#                   stddev= sd(Nuclear, na.rm=T),
#                   stderr=stddev/sqrt(N)
# )
# 
# # 
# 181/565
# 384/565
# 
# 22/225
# 203/225
# 
# 16/315
# 299/315
# 
# 5/174
# 169/174
# 
# (.9022*225+315*0.9492+174*.9712)/(225+315+174) - .6796
# 
# 
# .6796/.9397
